export function pie (data, month) {
  const legendText = []
  data && data.forEach(item => {
    legendText.push(item.name)
  })
  var option = {
    backgroundColor: '#fff',
    title: {
      text: '支出情况(元)',
      left: 'center',
      top: 0,
      textStyle: {
        color: '#666',
        fontSize: 15
      }
    },
    legend: {
      data: legendText,
      bottom: 'left',
      orient: 'horizontal'
    },
    tooltip: {
      trigger: 'item',
      formatter: '{b} : {c} ({d}%)'
    },
    visualMap: {
      show: false,
      min: 80,
      max: 600,
      inRange: {
        colorLightness: [0, 1]
      }
    },
    series: [
      {
        type: 'pie',
        radius: '55%',
        // radius: ['40%', '75%'],
        // center: ['50%', '50%'],
        data: data.sort(function (a, b) {
          return a.value - b.value
        }),
        //roseType: 'radius',//每个区域的角度大小
        label: {
          normal: {
            textStyle: {
              color: 'rgba(0, 0, 0, 0.9)'
            }
          }
        },
        labelLine: {
          normal: {
            lineStyle: {
              color: 'rgba(0, 0, 0,1)'
            },
            smooth: 0.2,
            length: 10,
            length2: 10
          }
        },
        itemStyle: {
          normal: {
            borderColor: '#fff',
            borderWidth: 2,
            borderRadius: 20,
            label: {
              textStyle: {color: 'white'},
              show: true,
              formatter: '{b} : \n{c} ({d}%)',
            },
            labelLine: {show: true},
            color: function (params) {
              let colorList = [
                '#FA897B',
                '#FFDD94',
                '#D0E6A5',
                '#dd6161'
              ]
              let colorItem = colorList[params.dataIndex]
              return colorItem
            }
          }
        },
        animationType: 'scale',
        animationEasing: 'elasticOut',
        animationDelay: function (idx) {
          return Math.random() * 200
        }
      }
    ]
  }
  return option
}

export function pieTwo (data, year) {
  const legendText = []
  data && data.forEach(item => {
    legendText.push(item.name)
  })
  var option = {
    backgroundColor: '#fff',
    title: {
      text: year + '结算情况(元)',
      subtext: '',//副标题
      left: 'center',
      top: 0,
      textStyle: {
        color: '#666',
        fontSize: 15
      }
    },
    legend: {
      data: legendText,
      bottom: 'left',
      orient: 'horizontal'
    },
    tooltip: {
      trigger: 'item',
      formatter: '{b} : {c} ({d}%)'
    },
    graphic: {
      type: 'text',
      left: 'center',
      top: 'center',
      style: {
        // text: '总数',
        text:
          data.reduce((n, i) => {
            return (n += i.value)
          }, 0).toFixed(2) + '\n总收入',
        textAlign: 'center',
        fill: '#333',
        width: 30,
        height: 30,
        fontSize: 14
      }
    },
    series: [
      {
        type: 'pie',
        // radius: '55%',
        radius: ['35%', '65%'],
        data: data.sort(function (a, b) {
          return a.value - b.value
        }),
        label: {

          normal: {
            textStyle: {
              color: 'rgba(0,0,255,.6)'
            }
          }
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold',
            formatter: '{b}: {d}'

          }
        },
        labelLine: {
          show: true,
          normal: {
            lineStyle: {
              color: 'rgba(0, 0, 0,1)'
            },
            smooth: 0.2,
            length: 10,
            length2: 20
          }
        },
        padAngle: 0,
        avoidLabelOverlap: true,
        itemStyle: {
          normal: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2,
            label: {
              position: 'inside',
              textStyle: {color: 'white'},
              show: true,
              fontWeight: 600,
              fontSize: 16,
              formatter: '{c}'
            },
            labelLine: {
              show: true
            },
            color: function (params) {
              let colorList = [
                '#67c23a',
                '#e6a23c'
              ]
              let colorItem = colorList[params.dataIndex]
              return colorItem
            }
          }
        },
        animationType: 'scale',
        animationEasing: 'elasticOut',
        animationDelay: function (idx) {
          return Math.random() * 200
        }
      }
    ]
  }
  return option
}

